#ifndef PACKET_HPP_
#define PACKET_HPP_


#include <string>
#include <vector>
#include <stdint.h>

/* As tempting as it may be, can not make this abstract; must read in a received packet
 * before its type can be determined. */
class Packet {

private:
    static const uint8_t startByte = 0x7E;
    std::vector<uint8_t> data;
    uint16_t packet_length;
    uint8_t get_checksum();
    uint8_t checksum;


public:
    Packet();
    virtual ~Packet();

    enum frame_type {
        at_cmd_ft = 0x08,
        tx_request_ft = 0x10,
        explicit_addressing_ft = 0x11
    };

    static const uint32_t node[2];
    const uint32_t upper_addr = 0x13a200;


    void assemble_header (std::vector<uint8_t> * header, std::vector<uint8_t> * payload);
    void createPacket();
    bool is_valid();

    virtual std::vector<uint8_t> * get_payload();


    std::vector<uint8_t>* get_data() {
        return (&data);
    }

    static const uint8_t get_startByte() {
        return (startByte);
    }
};

void push_back_32 (std::vector<uint8_t> * payload, uint32_t data);
void push_back_16 (std::vector<uint8_t> * payload, uint16_t data);


#endif /* PACKET_HPP_ */
